package com.hengxinguotong.hxgtwygsp.widget;

import android.content.Context;

import com.hengxinguotong.hxgtwygsp.R;
import com.hengxinguotong.hxgtwygsp.model.Month;
import com.hengxinguotong.hxgtwygsp.model.Year;

import java.util.List;

/**
 * TODO
 *
 * @author hjz
 * @version V1.0.0
 * @since 2019/4/10 10:52
 */

public class MonthPW extends DoubleListPW<Year, Month>
{
    private List<Year> yearList;
    private WheelAdapter<Year> leftAdapter;
    private WheelAdapter<Month> rightAdapter;
    private List<Month> rightList;

    public MonthPW(Context context, int width)
    {
        super(context, width);
    }

    @Override
    public void initData(List<Year> list)
    {
        this.yearList = list;
        leftAdapter = new WheelAdapter<Year>(context, list);
        leftRecycler.setViewAdapter(leftAdapter);
        leftRecycler.setVisibleItems(3);
        leftRecycler.setDrawShadows(false);
        leftRecycler.setCenterLineColor(R.color.c3F3CF4);
        leftRecycler.addChangingListener((wheel, oldValue, newValue) ->
        {
            rightList = list.get(newValue).getMonthList();
            rightAdapter.setTextList(rightList);
            rightAdapter.notifyDataSetChanged();
        });
        rightList = list.get(0).getMonthList();
        rightAdapter = new WheelAdapter<Month>(context, rightList);
        rightRecycler.setViewAdapter(rightAdapter);
        rightRecycler.setVisibleItems(3);
        rightRecycler.setDrawShadows(false);
        rightRecycler.setCenterLineColor(R.color.c3F3CF4);
    }

    @Override
    void onConfirm(int leftIndex, int rightIndex)
    {
        Year year = yearList.get(leftIndex);
        callback.onClickPW(year, year.getMonthList().get(rightIndex));
    }
}
